package com.ruoyi.qt.controller;

import java.util.List;

import com.ruoyi.qt.domain.QtNote;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.qt.domain.QtRecord;
import com.ruoyi.qt.service.IQtRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 做题记录Controller
 * 
 * @author zqq
 * @date 2021-12-06
 */
@RestController
@RequestMapping("/qt/record")
public class QtRecordController extends BaseController
{
    @Autowired
    private IQtRecordService qtRecordService;

    /**
     * 查询做题记录列表
     */
    @PreAuthorize("@ss.hasPermi('qt:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(QtRecord qtRecord)
    {
        startPage();
        List<QtRecord> list = qtRecordService.selectQtRecordList(qtRecord);
        return getDataTable(list);
    }

    /**
     * 导出做题记录列表
     */
    @PreAuthorize("@ss.hasPermi('qt:record:export')")
    @Log(title = "做题记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QtRecord qtRecord)
    {
        List<QtRecord> list = qtRecordService.selectQtRecordList(qtRecord);
        ExcelUtil<QtRecord> util = new ExcelUtil<QtRecord>(QtRecord.class);
        return util.exportExcel(list, "做题记录数据");
    }

    /**
     * 获取做题记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('qt:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") String recordId)
    {
        return AjaxResult.success(qtRecordService.selectQtRecordByRecordId(recordId));
    }

    /**
     * 新增做题记录
     */
    @PreAuthorize("@ss.hasPermi('qt:record:add')")
    @Log(title = "做题记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QtRecord qtRecord)
    {
        return toAjax(qtRecordService.insertQtRecord(qtRecord));
    }

    /**
     * 修改做题记录
     */
    @PreAuthorize("@ss.hasPermi('qt:record:edit')")
    @Log(title = "做题记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QtRecord qtRecord)
    {
        return toAjax(qtRecordService.updateQtRecord(qtRecord));
    }

    /**
     * 删除做题记录
     */
    @PreAuthorize("@ss.hasPermi('qt:record:remove')")
    @Log(title = "做题记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable String[] recordIds)
    {
        return toAjax(qtRecordService.deleteQtRecordByRecordIds(recordIds));
    }


}
